package com.lu.pojo.loop;
/**
 * @Author：luzhenfang
 * @Date: 2020 3 20
 * @Desc: 成绩统计打分
 */

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;


public class MaxSocre {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        List<Integer> arr = new ArrayList<>();
        // 闭环
        System.out.println("请输入学生成绩(整数)");
        System.out.println("一行一个");
        System.out.println("非整数 开始计算");

        while (true){
            int score =0;

            try{
                score = scanner.nextInt();
                arr.add(score);
            }catch (Exception e) {
                // 终止输入
                break;
            }
        }

        int maxScore =findMax(arr.toArray());
        System.out.println("-----------------------");
        System.out.printf("%s%10s%10s\n","ID","SCORE","GRADE");
        for (int i=0;i<arr.size();i++){
            System.out.printf("%d%9d%10s\n",i+1,arr.get(i),makeGrade(maxScore,arr.get(i)));
        }
        System.out.println("-----------------------");
        System.out.println("MaxScore: "+maxScore);
    }


    public static String makeGrade(int maxScore ,int score){
        if (score>=maxScore-10){
            return "A";
        }else if(score>=maxScore-20){
            return "B";
        }else if(score>=maxScore-30){
            return "C";
        }else{
            return "D";
        }
    }

    public static int findMax(Object[] arr){
        int max =0;
        for (int i = arr.length - 1; i >= 0; i--) {
            if ((int)arr[i]>max)
                max=(int)arr[i];
        }
        return max;
    }


}
